package nio;

import org.junit.jupiter.api.Test;

import java.io.*;
import java.nio.channels.FileChannel;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @program: comprehensive-service
 *
 * @description: 拷贝文件
 *
 * @author: 窦绍飞
 *
 * @create: 2021-11-25 10:12
 **/
public class NioChannelTest_4 {
	public static void main(String[] args) throws IOException {
		File file = new File("springboot_netty/src/test/java/1.txt");
		FileInputStream fileInputStream = new FileInputStream(file);

		FileChannel channel = fileInputStream.getChannel();

		FileOutputStream fileOutputStream = new FileOutputStream("springboot_netty/src/test/java/4.txt");
		FileChannel channel1 = fileOutputStream.getChannel();
		// 从当前通道 赋值到 给定通道
//		channel.transferTo( 0, channel.size(),channel1);
		//从给定通道 给调用方通道
		channel1.transferFrom(channel,0,channel.size());
		channel.close();
		channel1.close();
		fileInputStream.close();
		fileOutputStream.close();
	}

	@Test
	public void test(){
		String json  = "{\n" +
				"    \"birthday\":\"1970-09-24\",\n" +
				"    \"gender\":\"2\",\n" +
				"    \"mallId\":\"010101\",\n" +
				"    \"openid\":\"ouJdt6aSC8vtKqIAsyTScG7ibmIA\",\n" +
				"    \"channel\":\"6\",\n" +
				"    \"phoneNumber\":\"13691282226\",\n" +
				"    \"thirdMemberId\":\"24682322\",\n" +
				"    \"name\":\"x y l\"\n" +
				"}";
		System.out.println(removeSpecialCharacters(json));
	}
	/** 去除字符串的特殊字符 */
	public static String removeSpecialCharacters(String params) {
		String regEx = "[`~!@#$%^&*()+=|''.<>/?~！@#￥%……&*（）——+|【】‘；：”“’。，、？]";
		Pattern p = Pattern.compile(regEx);
		Matcher m = p.matcher(params);
		return m.replaceAll("").trim();
	}
}
